#include "config.h"
#include "GPIO_InIt.h"
#include "IR_Exit.h"
#include "MyEEPROM.h"

u16 i;
u8 Address;
u8 Command;
unsigned int pwm_duty_cycle = 0; // 初始PWM占空比为50%

void UART_config(void)
{
	COMx_InitDefine		COMx_InitStructure;					
	COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;
	COMx_InitStructure.UART_BRT_Use   = BRT_Timer1;
	COMx_InitStructure.UART_BaudRate  = 9600;
	COMx_InitStructure.UART_RxEnable  = ENABLE;
	COMx_InitStructure.BaudRateDouble = DISABLE;
	COMx_InitStructure.UART_Interrupt = ENABLE;
	COMx_InitStructure.UART_Priority  = Priority_0;
	COMx_InitStructure.UART_P_SW      = UART1_SW_P30_P31;
	UART_Configuration(UART1, &COMx_InitStructure);
	EA=1;//中断总开关
}

void main()
{
	GPIO_Init();
	UART_config();
	Timer1_Init();
	while(1)
	{	
		
		for(i=0;i<90;i++)
		{
			Delay_ms(1);
			pwm_duty_cycle=i;
		}
		for(i=100;i>=10;i--)
		{
			Delay_ms(1);
			pwm_duty_cycle=i;
		}
	}
}

void Timer1_ISR() interrupt 3
{
    static unsigned int pwm_counter = 0;

    pwm_counter++;
    if (pwm_counter >= pwm_duty_cycle)
        LED = 0; // 将P10口置低，产生PWM波形
    else
        LED = 1; // 将P10口置高，产生PWM波形

    if (pwm_counter >= 100)
        pwm_counter = 0; // 重置计数器
}

	
